package com.xy.day4.dao;

import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;
import com.xy.day4.entity.Animal;
import com.xy.day4.util.RedisCache;
@MapperScan
@CacheNamespace(implementation=RedisCache.class)
public interface AnimalMapper {
    @Delete({
        "delete from animal",
        "where animal_id = #{animalId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer animalId);

    @Insert({
        "insert into animal (animal_id, animal_name, ",
        "animal_weight, type_id)",
        "values (#{animalId,jdbcType=INTEGER}, #{animalName,jdbcType=VARCHAR}, ",
        "#{animalWeight,jdbcType=VARCHAR}, #{type.typeId,jdbcType=INTEGER})"
    })
    int insert(Animal record);

    int insertSelective(Animal record);

    @Select({
        "select",
        "animal_id, animal_name, animal_weight, type_id",
        "from animal",
        "where animal_id = #{animalId,jdbcType=INTEGER}"
    })
    @ResultMap("com.xy.day4.dao.AnimalMapper.BaseResultMap")
    Animal selectByPrimaryKey(Integer animalId);

    @Select({
        "select",
        "animal_id, animal_name, animal_weight, type_id",
        "from animal"
    })
    @ResultMap("com.xy.day4.dao.AnimalMapper.BaseResultMap")
    List<Animal> selectAll();
    
    int updateByPrimaryKeySelective(Animal record);

    @Update({
        "update animal",
        "set animal_name = #{animalName,jdbcType=VARCHAR},",
          "animal_weight = #{animalWeight,jdbcType=VARCHAR},",
          "type_id = #{type.typeId,jdbcType=INTEGER}",
        "where animal_id = #{animalId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Animal record);
}